home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
btrieve
/
btrvph.c
< prev
next >
Wrap
Text File
|
1991-08-19
|
6KB
|
144 lines
/*--------------------------------------------------------------------------*/
/* */
/* WatCom C interface to the Btrieve Record Manager */
/* */
/* Watcom v8.0 interface for use with Phar Lap 4.0 */
/* By Adam White */
/* Westinghouse Canada Inc. */
/* 416-528-8811 ext 3420 */
/* */
/* Configure Phar Lap with 64K callbufs */
/* ie: CFIG386 RUN386 -callbufs 64 */
/* */
/* Call BTRVinstalled() to determine if btrieve is installed */
/*--------------------------------------------------------------------------*/
#define BTR_ERR 20 /* record manager not started */
#define BTR_INT 0x7B /* Btrieve interrupt vector */
#define BTR_OFFSET 0x33 /* Btrieve offset within segment */
#define VARIABLE_ID 0x6176 /* id for variable length records - 'va' */
int BTRVerr; /* global error flag */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <dos.h>
typedef unsigned short int INT;
#define SINT short
typedef struct /* structure passed to Btrieve Record Manager */
{
char *bufAddress; /* callers data buffer Address */
INT bufLength; /* length of data buffer */
char *curAddress; /* user position block Address */
char *fcbAddress; /* Address of disk FCB */
INT function; /* requested function */
char *keyAddress; /* Address of user's key buffer */
char keyLength; /* length of user's key buffer */
char keyNumber; /* key of reference for request */
INT *statAddress; /* Address of status word */
INT xfaceID; /* language identifier */
} BTRIEVE_PARMS;
typedef struct { /* Phar Lap parameter block */
INT itrpt;
INT ds;
INT es;
INT fs;
INT gs;
int eax;
int edx; } PARM_BLOCK;
int BTRV (int operation,char *posBlock,char *dataBuf,int *dataLen,char *keyBuf,int keyNum)
{
union REGS regs;
struct SREGS sregs;
BTRIEVE_PARMS __far *xData;
PARM_BLOCK pblock;
char __far *interModeBuffer;
char __far *protModeCallBufFCB;
char __far *protModeCallBufDataBuf;
char __far *protModeCallBufKeyBuf;
int bufferUsed=0,realModeBufferAddress;
INT __far *stat; /* status of Btrieve call */
/* */
/* Move user parameters to xData, the block where Btrieve expects them.*/
/* */
segread(&sregs);
regs.x.eax=0x250D; /* get address of call buffer from Phar Lap */
int386x(0x21, ®s, ®s, &sregs);
interModeBuffer=MK_FP(sregs.es,regs.x.edx);
realModeBufferAddress=regs.x.ebx;
xData=(BTRIEVE_PARMS __far *) interModeBuffer;
xData->function = operation;
xData->bufLength = *dataLen;
xData->keyLength = 255; /* use max since we don't know */
xData->keyNumber = keyNum;
xData->xfaceID = VARIABLE_ID;
bufferUsed=sizeof(*xData);
/* all pointers and the data pointed to must appear in the callbuf */
stat=(INT __far *) interModeBuffer+bufferUsed;
*stat=1;
xData->statAddress = (INT *) realModeBufferAddress+bufferUsed;
bufferUsed+=sizeof(INT);
_fmemcpy(interModeBuffer+bufferUsed,(char __far *) posBlock,128);
protModeCallBufFCB=interModeBuffer+bufferUsed;
xData->fcbAddress =(char *) realModeBufferAddress+bufferUsed;
xData->curAddress =(char *) realModeBufferAddress+bufferUsed + 38;
bufferUsed+=128;
_fmemcpy(interModeBuffer+bufferUsed,(char __far *) dataBuf,*dataLen);
protModeCallBufDataBuf=interModeBuffer+bufferUsed;
xData->bufAddress =(char *) realModeBufferAddress+bufferUsed;
bufferUsed+=*dataLen;
_fmemcpy(interModeBuffer+bufferUsed,(char __far *) keyBuf,255);
protModeCallBufKeyBuf=interModeBuffer+bufferUsed;
xData->keyAddress =(char *) realModeBufferAddress+bufferUsed;
bufferUsed+=255;
/* */
/* Make call to the Btrieve Record Manager. */
/* */
pblock.itrpt=BTR_INT;
pblock.ds=realModeBufferAddress>>16;
pblock.edx=realModeBufferAddress;
regs.x.eax=0x2511;
segread (&sregs);
regs.x.edx=FP_OFF((char __far *) &pblock);
sregs.ds=FP_SEG((char __far *) &pblock);
int386x(0x21, ®s, ®s, &sregs);
/* copy data back to prot. mode memory */
_fmemcpy((char __far *) posBlock,protModeCallBufFCB,128);
_fmemcpy((char __far *) dataBuf,protModeCallBufDataBuf,xData->bufLength);
_fmemcpy((char __far *) keyBuf,protModeCallBufKeyBuf,xData->keyLength);
*dataLen = xData->bufLength;
return(BTRVerr=*stat); /* return status */
}
/* This function determines if Btrieve has been installed */
/* returns 1 if installed else 0 */
/* call this fuction before making any btrieve calls */
BTRVinstalled()
{
int retval=0;
union REGS regs;
struct SREGS sregs;
segread (&sregs);
regs.x.eax=0x2503;
regs.x.ecx=BTR_INT;
int386x(0x21, ®s, ®s, &sregs);
if(regs.w.bx==BTR_OFFSET)
retval=1;
return(retval);
}